#include "Terrain.h"
#include<assert.h>
#include<stdlib.h>
void terInit(Terrain* ter,int dimx,int dimy)
{
    int i;
    assert(dimx>0);
    assert(dimy>0);
    ter->dimx=dimx;
    ter->dimy=dimy;
    ter->tab=(char**)malloc(ter->dimy*sizeof(char*));
    for(i=0;i<ter->dimy;i++)
    {
        ter->tab[i]=(char*)malloc(ter->dimx*sizeof(char));
    }
}

void terLibere(Terrain* ter)
{
    int i;
    for(i=0;i<ter->dimy;i++)
    {
        free(ter->tab[i]);
    }
    free(ter->tab);
    ter->dimx=0;
    ter->dimy=0;
    ter->tab=NULL;
}

int terGetDimx(const Terrain* ter)
{
    return ter->dimx;
}

int terGetDimy(const Terrain* ter)
{
    return ter->dimy;
}

void terSetXY(Terrain* ter,int x,int y,const char car)
{
    assert(x>0 && y>0);
    assert(x<ter->dimx-1 && y<ter->dimy-1);
    ter->tab[y][x]=car;
}

const char terGetXY(const Terrain* ter,int x,int y)
{
    assert(x>=0);
    assert(y>=0);
    assert(x<ter->dimx);
    assert(y<ter->dimy);
    return ter->tab[y][x];
}

bool terPositionValide(const Terrain* ter,int x,int y)
{
    if(x>=0 && y>=0 && x<ter->dimx && y<ter->dimy && (ter->tab[y][x] ==' ' || ter->tab[y][x]=='V'))
    {
        return true;
    }
    else
    {
        return false;
    }
}













